package aar.test.tessocr.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.List;

import aar.test.tessocr.interfaces.BaseAdapter;
import aar.test.tessocr.model.OrderModel;
import clx.tessocr.ocreng.R;

/**
 * author: sunshine
 * created on: 2023/9/25 16:25
 * description:
 */
public class OrderListAdapter extends BaseAdapter<OrderListAdapter.OrderListItemHolder> {
    private List<OrderModel> mList;
    private Context context;


    public OrderListAdapter(Context mContext, @NonNull List<OrderModel> mList) {
        this.mList = mList;
        this.context = mContext;
    }

    @Override
    public OrderListAdapter.OrderListItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.order_list_item, parent, false);
        OrderListAdapter.OrderListItemHolder holder = new OrderListAdapter.OrderListItemHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull OrderListAdapter.OrderListItemHolder holder, final int position) {
        holder.tv_name.setText(mList.get(position).getCompany());
        holder.tv_num.setText(mList.get(position).getNum() + "份");
        holder.tv_gekou.setText(mList.get(position).getGridnum());
        holder.tv_time.setText(mList.get(position).getAdd_at());

        holder.tv_open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mViewClickListener) {
                    mViewClickListener.borrowKey(position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class OrderListItemHolder extends RecyclerView.ViewHolder {
        TextView tv_name;
        TextView tv_num;
        TextView tv_gekou;
        TextView tv_time;
        TextView tv_open;

        public OrderListItemHolder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.title);
            tv_num = itemView.findViewById(R.id.tv_num);
            tv_gekou = itemView.findViewById(R.id.tv_gekou);
            tv_time = itemView.findViewById(R.id.tv_time);
            tv_open = itemView.findViewById(R.id.tv_open);
        }
    }

    public interface ViewClickListener {
        void borrowKey(int pos);
    }

    public void setViewClickListener(OrderListAdapter.ViewClickListener mViewClickListener) {
        this.mViewClickListener = mViewClickListener;

    }


    private OrderListAdapter.ViewClickListener mViewClickListener;
}
